package constants

import "jvmgo/ch09/instructions/base"
import "jvmgo/ch09/rtda"

/*
    把隐含在操作码中的常量值推入栈顶
    常量来自三个地方，操作码、操作数、运行时常量池
 */

//把null入栈
type ACONST_NULL struct {
    base.NoOperandsInstruction
}

func (self *ACONST_NULL) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushRef(nil)
}

//把double值0入栈
type DCONST_0 struct {
    base.NoOperandsInstruction
}

func (self *DCONST_0) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushDouble(0.0)
}

//把double值1入栈
type DCONST_1 struct {
    base.NoOperandsInstruction
}

func (self *DCONST_1) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushDouble(1.0)
}

//把float值0入栈
type FCONST_0 struct {
    base.NoOperandsInstruction
}

func (self *FCONST_0) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushFloat(0.0)
}

//把float值1入栈
type FCONST_1 struct {
    base.NoOperandsInstruction
}

func (self *FCONST_1) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushFloat(1.0)
}

//把float值2入栈
type FCONST_2 struct {
    base.NoOperandsInstruction
}

func (self *FCONST_2) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushFloat(2.0)
}

//把int值-1入栈
type ICONST_M1 struct {
    base.NoOperandsInstruction
}

func (self *ICONST_M1) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushInt(-1)
}

//把int值0入栈
type ICONST_0 struct {
    base.NoOperandsInstruction
}

func (self *ICONST_0) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushInt(0)
}

//把int值1入栈
type ICONST_1 struct {
    base.NoOperandsInstruction
}

func (self *ICONST_1) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushInt(1)
}

//把int值2入栈
type ICONST_2 struct {
    base.NoOperandsInstruction
}

func (self *ICONST_2) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushInt(2)
}

//把int值3入栈
type ICONST_3 struct {
    base.NoOperandsInstruction
}

func (self *ICONST_3) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushInt(3)
}

//把int值4入栈
type ICONST_4 struct {
    base.NoOperandsInstruction
}

func (self *ICONST_4) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushInt(4)
}

//把int值5入栈
type ICONST_5 struct {
    base.NoOperandsInstruction
}

func (self *ICONST_5) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushInt(5)
}

//把long值0入栈
type LCONST_0 struct {
    base.NoOperandsInstruction
}

func (self *LCONST_0) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushLong(0)
}

//把long值1入栈
type LCONST_1 struct {
    base.NoOperandsInstruction
}

func (self *LCONST_1) Execute(frame *rtda.Frame) {
    frame.OperandStack().PushLong(1)
}